<template>
  <div class="layui-layout layui-layout-admin">
    <div class="adminnav1">
      <Pagetop></Pagetop>
    </div>
    <div class="adminnav2">
      <Secondnav urlname="user"></Secondnav>
    </div>

    <!-- 主体内容 -->
    <div class="layui-body kedou-admin" id="LAY_app_body app">
      <div class="layadmin-tabsbody-item layui-show">
        <div class="pagelist">
          <div class="layui-card-body">
            <fieldset class="layui-elem-field layui-field-title">
              <legend>门店列表</legend>
            </fieldset>
          </div>
          <div class="pagetop">
            <Search :seadate="searchArr"></Search>
          </div>
          <div class="layui-card-body">
          	<div class="buttop">
             
              <button type="button" class="layui-btn  layui-btn-warm" v-if="type==1" @click="pxfun">按推荐排序</button>
            </div>
            <Tables :fdate="pdate" :result="res" height="430" :totalCount="totalRows" :pageNumber="curindex"
              :fbtn="btn"></Tables>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import Pagetop from "../../common/pagetop.vue";
import Secondnav from "../../common/secondnav.vue";
import Tables from "../../common/tables.vue";
import Search from "../../common/search.vue";
export default {
  name: "shoplist",
  components: { Pagetop, Secondnav, Tables, Search },
  data () {
    return {
      pdate: [], //表头
      res: "", //内容
      totalRows: "", //总数量
      curindex: 1, //页数
      btn: [], //按钮
      searchArr: [], //搜索
      isShow: false,
      seapram: "",
      type: localStorage.getItem("type")
    };
  },
  mounted () {
    this.getdate();
    this.getsearch();
  },
  methods: {
    getdate: function () {
      var _this = this;
      var url = "/shop/bapi/v1.9/shops";
      var type = localStorage.getItem("type");
      url=dourl(url)
      if (_this.seapram) {
        var dates = {
          size: pageSize,
          page: _this.curindex
          //sort:'createAt,DESC',
          //'status.equals':'ENABLE'
        };
        var res = _this.seapram;
        for (var i = 0; i < res.length; i++) {
        	if(res[i].val){
          dates[res[i].key + '.equals'] = res[i].val;
         }
        }
      } else {
        var dates = {
          size: pageSize,
          page: _this.curindex
          //sort:'createAt,DESC',
          //'status.equals':'ENABLE'
        };
      }
      if(this.px==1){
      	dates.sort='ranking,desc'
      }
      //alert(url+"//"+JSON.stringify(dates))
      ajaxRequest(url, "GET", "json", dates, function (ret, err) {
        //alert(url+"//"+JSON.stringify(ret))
        var arr = [];
        arr[0] = [
          { field: "id", title: "门店ID" },
          { field: "name", title: "门店名称" },
          {
            field: "dealer",
            title: "联系方式",
            templet: function (d) {
              if(d.dealer.mobile ==null){
                return ''
              }else{
                return d.dealer.mobile;
              }
            }
          },
          {
            field: "rotationPictures",
            title: "图片",
            templet:
              '<div><img src="{{d.rotationPictures}}" style="display: inline-block; height: 100%;"></div>'
          },
          {
            field: "activeStatus",
            title: "是否启用",
            templet: function (d) {
              if (d.activeStatus == "ENABLE") return "是";
              else return "否";
            }
          },
          {
            field: "perCapita",
            title: "人均消费(元)",
            templet: function (d) {
              return d.perCapita / 100;
            }
          },
          {
            field: "shopType",
            title: "店铺类型",
            templet: function (d) {
              return d.shopType.name;
            }
          },
          { field: "salesVolume", title: "全店销量" },
          { field: "score", title: "总评分" },
          {
            field: "ranking",
            title: "推荐值"
          },
          {
            field: "createAt",
            title: "创建时间",
            templet: function (d) {
              return FormatDate(d.createAt, 3);
            }
          },
          {
            field: "right",
            title: "操作",
            fixed: "right",
            templet: function (d) {
              var str =
                '<a class="layui-btn layui-btn-xs layui-btn-normal" lay-event="detail">详情</a>';
              if (type == 1) {
              	var str5='<a class="layui-btn layui-btn-xs  layui-btn-edit" lay-event="upgrade">设置推荐值</a>';
              	return str +str5;
              }
              else{
              	return str;
              }
              
            }
          }
        ];
        _this.pdate = arr;
        _this.res = ret.data.list; //res1;
        _this.totalRows = ret.data.totalRows;
        _this.curindex = ret.data.page+1;
      });
    },
    getsearch: function () {
      var arr = [{ field: "name", title: "门店名称", type: "input" }];
      this.searchArr = arr;
    },
    page: function (index, obj) {
      //alert(JSON,stringify(obj))
      this.curindex = index;
      this.getdate();
    },
    sousuo: function (pram) {
      //alert(JSON.stringify(pram))
      this.seapram = pram;
      this.res = "";
      this.totalRows = "";
      this.curindex = "";
      this.getdate();
    },
    pxfun:function(){
    	this.px=1
    	this.getdate()
    },
    upgradeInfo:function(data){
    	var _this = this;
    	layer.open({
			    type: 1 //Page层类型
			    ,btn:["确定","取消"]
			    ,title: '设置推荐值'
			    ,skin: 'layui-layer-prompt'
			    ,content: "<div><input id='transfer-msg' type='text' class='layui-layer-input' value='' placeholder='输入数字，越大排越前'></div>"
			    ,yes: function(index, layero){
			      var val=$(layero).find("#transfer-msg").val();
			      var url = "/shop/aapi/v1.9/shops/updateRan";
			      var dates={
						  "id":data.id,
						  "ranking":val
						}
			      ajaxRequest(url, 'PUT', "json", dates, function(ret, err) {
			        layer.msg("操作成功");
			        setTimeout(function() {
			        	layer.close(index);
			          _this.getdate();
			        }, 800);
			      });
			    }
			});
    },
    detailInfo: function(data) {
      var _this = this;
      var id = data.id;
      layer.open({
        type: 2,
        title: "门店信息",
        shadeClose: false, //点击遮罩关闭
        content: baseurl + "shopdetail",
        area: _this.screens() < 2 ? ["55%", "65%"] : ["550px", "650px"],
        success: function(layero, index) {
          var iframeWin = window[layero.find("iframe")[0]["name"]];
          iframeWin.getdates(data);
        }
      });
    },
    screens: function () {
      return screen();
    }
  },
  updated: function () {
    this.isShow = true;
    layui.use("form", function () {
      var form = layui.form;
      form.render();
    });
  }
};
</script>
<style scoped>
/**/
</style>
